@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">

        @if(count($errors))
            <div class="alert alert-danger">
                <ul>
                    @foreach($errors->all() as $err)
                        <li>{{ $err }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
        

        <div class="section_body">
            <div id="wrapper">
                <div id="container">
                    <!--头部，相册选择和格式选择-->
                    <div id="uploader">
                        <div class="queueList">
                            <div id="dndArea" class="placeholder">
                                <div id="filePicker"></div>
                                <p>上传一张图片</p>
                            </div>
                        </div>
                        <div class="statusBar" style="display:none;">
                            <div class="progress">
                                <span class="text">0%</span>
                                <span class="percentage"></span>
                            </div><div class="info"></div>
                            <div class="btns">
                                <div id="filePicker"></div><div class="uploadBtn">开始上传</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <em style="display:none" id="upload_button">上传</em>
        </div>

        <form id="defaultForm" method="post">
            {{ csrf_field() }}
            <div class="form-group">
                <label class="control-label">IMG</label>
                @foreach($data->pic as $img)
                    <span style="position: relative;">
                    <img style="max-width: 10%" src="{{$img}}">
                    <span style="position: absolute;right: 5px;top: -50px" class="glyphicon glyphicon-remove" aria-hidden="true" onclick="delete_thumb({{$data->id}},'{{img($img)}}',this)"></span>
                    </span>
                @endforeach
                
            </div>
            <div class="form-group required">
                <label class="control-label">分类</label>
                <select class="form-control" name="type">
                    <option value="">请选择分类</option>
                    @foreach($cat as $k=>$v)
                        <option value="{{ $k}}" @if($data->type==$k)selected=""@endif >{{ $v}}</option>
                    @endforeach
                </select>
            </div>
            
            

            <div class="form-group required">
                <label class="control-label">内容</label>
                <textarea name="content" class="form-control">{{$data->content}}</textarea>
            </div>
            <div class="form-group required">
                <label class="control-label">分享数量</label>
                <input name="pid" type="text" class="form-control" value="{{$data->share_number}}">
            </div>
            <div class="form-group required">
                <label class="control-label">是否上线</label>
                <label><input class="form-control" type="radio" name="status" value="1" @if($data->status==1)checked=""@endif />上线 </label>
                <label><input class="form-control" type="radio" name="status" value="0" @if($data->status==0)checked=""@endif />下线</label>
            </div>
            
            <div class="form-group required">
                <label class="control-label">评论</label>
                <textarea name="comment_content" class="form-control">{{$comment->content}}</textarea>
            </div>
            
            
            <div class="form-group">
                <input id="goods_img" type="hidden" name="pic" value="" />
                <button class="btn btn-primary btn-block" type="submit">保存</button>
            </div>
        </form>
    </div>
@endsection


@section('foot')
    
   

    
    <script type="text/javascript" src="/libs/webupload/dist/webuploader.js?v=<?=config('version')?>"></script>
    <script type="text/javascript" src="/libs/webupload/uploadone.js?v=<?=config('version')?>"></script>
    <link rel="stylesheet" type="text/css" href="/libs/webupload/style.css?v=<?=config('version')?>" />
    <link rel="stylesheet" type="text/css" href="/libs/webupload/css/webuploader.css?v=<?=config('version')?>" />


<script src="{{ asset('libs/bootstrapvalidator-master/dist/js/bootstrapValidator.min.js') }}?v=<?=config('version')?>"></script>
<link href="{{ asset('libs/bootstrapvalidator-master/dist/css/bootstrapValidator.min.css') }}?v=<?=config('version')?>" rel="stylesheet" type="text/css">
<script type="text/javascript">
$.ajaxSetup({
    headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
})
$(document).ready(function() {
    $('#defaultForm').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        
        fields: {
            theme_id: {
                validators: {
                    notEmpty: {},
                }
            },
            title: {
                validators: {
                    notEmpty: {},
                }
            },
            pid: {
                validators: {
                    notEmpty: {},
                },
                regexp:{
                    regexp: /^[0-9]+$/,
                    message: 'pid'
                }
            },
            unique_name:{
                validators: {
                    notEmpty: {},
                    remote: {
                        type: 'POST',
                        url: '/theme/ajax_theme_unique_exists',
                        message: "unique name 已经存在",
                        delay: 300,
                        data:function(validator) {
                           return {
                               'unique_name': $('[name="unique_name"]').val(),
                           }
                        }
                    }
                }
            }
        }
    });
});

function delete_thumb(id,img,obj) {
    $.post("/share/ajax_delete_pic",{id:id,img:img},function(json){

    },"json");
    $(obj).parent().hide();
}
</script> 
@endsection
